package org.sun.web.util;

import java.util.Comparator;
import java.util.Map;

@SuppressWarnings({ "unchecked", "rawtypes" })
public class ListComparator implements Comparator{

	@Override
	public int compare(Object o1, Object o2) {
		
		Map<String,Object> item1=(Map<String,Object>)o1;
		Map<String,Object> item2=(Map<String,Object>)o2;
		int x1=Integer.parseInt(item1.get("x").toString());
		int x2=Integer.parseInt(item2.get("x").toString());
		int y1=Integer.parseInt(item1.get("y").toString());
		int y2=Integer.parseInt(item2.get("y").toString());
		if(x1<x2){
			if(y1<y2) return -1;
			else return 1;
		}else if(x1==x2){
			if(y1<y2) return -1;
			else return 1;
		}else{
			if(y1<y2) return -1;
			else return 1;
		}
	}
}
